#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 noet:
#
# $Id: install.py 2 2008-06-05 13:15:18Z wejradford $

"""
	install.py

Installs the yare plugin.
"""

__version__ = "$Revision: 2 $"
# $URL: http://yare-gedit-plugin.googlecode.com/svn/trunk/install.py $

import os, glob, ConfigParser, sys, shutil, logging, pwd, stat
from optparse import OptionParser

YARE_SOURCE = "yare"
YARE_PLUGIN = "yare.gedit-plugin"
def main():
	parser = OptionParser(__doc__)
	opts, args = parser.parse_args()
	# Setup (and perhaps clean) plugin directory.
	pluginDirectory = os.path.join(os.getenv("HOME"), ".gnome2", "gedit", "plugins")
	if not os.path.isdir(pluginDirectory):
		try:
			os.makedirs(pluginDirectory)
			print >> sys.stderr, "Creating plugin directory..."
		except Exception, e:
			parser.error("Error creating plugin directory\n%s" % str(e))
	sourceDir = os.path.join(os.path.dirname(__file__), YARE_SOURCE)
	targetDir = os.path.join(pluginDirectory, YARE_SOURCE)
	# Clean up existing copies.
	if os.path.exists(targetDir):
		answer = " "
		while answer not in "yn":
			answer = raw_input("Found existing plugin:\n%s\nRemove? [yYnN] " % targetDir).lower()
		if answer == "n":
			parser.error("Exiting...")
		print >> sys.stderr, "Removing existing plugin..."
		shutil.rmtree(targetDir)
	# Install.
	try:
		print >> sys.stderr, "Installing plugin..."
		shutil.copy(YARE_PLUGIN, pluginDirectory)
		shutil.copytree(sourceDir, targetDir)
	except Exception, e:
		parser.error("Error installing plugin:\n%s" % str(e))

if __name__ == '__main__':
	main()
# End of $URL: http://yare-gedit-plugin.googlecode.com/svn/trunk/install.py $
